﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

using XunPan.Web.Globals;
using System.Web.Security;
using SalePartial.Utility;


partial class mp_for_rad : System.Web.UI.MasterPage
{


	protected void Page_Load(object sender, System.EventArgs e)
	{

		if (!IsPostBack) {
			string targetFolder = GlobalUtility.GetFirstFolderNameFromModulePath(Request.Path);

			switch (targetFolder) {
				case "trade":


					string childFolder = GlobalUtility.GetFirstFolderNameFromModulePath(Request.Path.ToLower().Replace(targetFolder + "/", ""));

					switch (childFolder) {
						case "inbox":
							radMenuNavi.FindItemByValue("inbox").Selected = true;
							break;
						case "events":
							radMenuNavi.FindItemByValue("xunpan").Selected = true;
							break;
						case "resource":
							radMenuNavi.FindItemByValue("resource").Selected = true;
							break;
						default:
							radMenuNavi.FindItemByValue("publish").Selected = true;

							break;
					}

					break;
				case "warecube":
					radMenuNavi.FindItemByValue("warecube").Selected = true;
					break;
				case "user":
					radMenuNavi.FindItemByValue("account").Selected = true;
					break;
				case "management":
					radMenuNavi.FindItemByValue("management").Selected = true;

					break;
				default:
					radMenuNavi.FindItemByValue("home").Selected = true;
					break;
			}

			//首页
			radMenuNavi.FindItemByValue("home").NavigateUrl = GlobalSetting.UrlHomePage;

			//帐户管理

			if ((Page.User.Identity.IsAuthenticated)) {
				hlkReg.Visible = false;
				radMenuNavi.FindItemByValue("account").Visible = true;
				radMenuNavi.FindItemByValue("account").NavigateUrl = "~/user/account/profile.aspx";


				//企业账户
				if (Roles.IsUserInRole(Page.User.Identity.Name, "Purchase")) {
					//询盘管理
					radMenuNavi.FindItemByValue("xunpan").NavigateUrl = "~/trade/events/event_grid.aspx";
					radMenuNavi.FindItemByValue("publish").NavigateUrl = "~/trade/trade_item.aspx";

					//供应商库
					radMenuNavi.FindItemByValue("resource").NavigateUrl = "~/trade/resource/vendor_retrieval.aspx";

					//收件箱
					radMenuNavi.FindItemByValue("inbox").NavigateUrl = "~/trade/inbox/inbox_list.aspx";

				} else if (Roles.IsUserInRole(Page.User.Identity.Name, "Suppliers")) {
					radMenuNavi.FindItemByValue("publish").Visible = false;

					//我的询盘
					radMenuNavi.FindItemByValue("xunpan").NavigateUrl = "~/trade/events/event_list.aspx";
					radMenuNavi.FindItemByValue("xunpan").Text = "我的询盘";

					//询盘检索
					radMenuNavi.FindItemByValue("resource").NavigateUrl = "~/trade/resource/trade_retrieval.aspx";
					radMenuNavi.FindItemByValue("resource").Text = "询盘检索";

					//收件箱
					radMenuNavi.FindItemByValue("inbox").NavigateUrl = "~/trade/inbox/inbox_list.aspx";
				} else {
					//个人用户
					radMenuNavi.FindItemByValue("trade").Visible = false;


				}

			} else {
				//匿名用户
				hlkReg.Visible = true;
				radMenuNavi.FindItemByValue("account").Visible = false;
				radMenuNavi.FindItemByValue("account").NavigateUrl = "~/Error.aspx?ErrCode=3&url=~/user/account/profile.aspx";
				radMenuNavi.FindItemByValue("trade").Visible = false;

			}





		}
	}


	protected void hlkLogin_LoggingOut(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
	{
		if (string.IsNullOrEmpty(Page.User.Identity.Name)) {
			Response.Redirect("~/Error.aspx?ErrCode=3");
		}
	}

    public mp_for_rad()
	{
		Load += Page_Load;
	}

	//Protected Sub radMenuNavi_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles radMenuNavi.ItemClick
	//    Select Case e.Item.Value
	//        Case "xunpan"
	//            '询盘
	//            If Roles.IsUserInRole(Page.User.Identity.Name, "Purchase") Then
	//                Response.Redirect("~/trade/events/event_grid.aspx", True)

	//            End If
	//            If Roles.IsUserInRole(Page.User.Identity.Name, "Suppliers") Then
	//                Response.Redirect("~/trade/events/event_list.aspx", True)

	//            End If
	//        Case "publish"
	//            If Roles.IsUserInRole(Page.User.Identity.Name, "Purchase") Then
	//                Response.Redirect("~/trade/trade_item.aspx", True)
	//            End If

	//        Case "inbox"
	//            Response.Redirect("~/trade/inbox/inbox_list.aspx", True)

	//        Case "resource"
	//            If Roles.IsUserInRole(Page.User.Identity.Name, "Purchase") Then
	//                Response.Redirect("~/trade/resource/vendor_retrieval.aspx", True)

	//            End If
	//            If Roles.IsUserInRole(Page.User.Identity.Name, "Suppliers") Then
	//                Response.Redirect("~/trade/resource/trade_retrieval.aspx", True)

	//            End If
	//        Case "warecube"
	//            '零部件库

	//        Case "account"
	//            '帐户管理
	//            Dim urlTemp As String = "~/user/account/profile.aspx"
	//            If Page.User.Identity.Name <> "" Then
	//                Response.Redirect(urlTemp)
	//            Else
	//                Response.Redirect("~/Error.aspx?ErrCode=3&url=" + urlTemp)
	//            End If
	//        Case "management"
	//            '网站管理

	//        Case "home"
	//            Response.Redirect(GlobalSetting.UrlHomePage)

	//        Case Else


	//    End Select

	//End Sub
}
